// pages/mypassword/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    account:null, //账号
    password:null ,//密码
    prolist:null, 
    openid:null
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    let openid = that.data.openid
    that.setData({
      openid:options.openid
    })
    let prolist =  wx.getStorageSync('prolist')
    if(prolist){
      wx.switchTab({
        url: '../group/group',
      })
    }
  //  console.log(options.openid)
  },
  
  onuserNameInput(e){
    let that = this;
    let account = e.detail.value;
    that.setData({
      account:account
    })
  },
  onpasWInput(e){
    let that = this;
    let password = e.detail.value;
    that.setData({
      password:password
    })
  },
  /**绑定账号密码**/
  onregistered(e){
    let that = this;
    let account = that.data.account;
    let password = that.data.password;
    let openid = that.data.openid;
     if(account==null){
      wx.showToast({icon: 'none', title: '请输入用户名',duration: 2000 })
    }else if(password==null){
      wx.showToast({icon: 'none', title: '请输入密码',duration: 2000 })
    }else { 
      wx.request({
        url: 'https://wxtp.hephp.cn/Api/Bind/index',
        data:{
          uid:account,
          pass:password,
          openid:openid
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        method: "get",
        success(res){
          console.log(res);
          let prolist = res.data;
          if(prolist.code==200){
          wx.setStorageSync('prolist',prolist)
            wx.switchTab({
              url: '../group/group',
            })
          }else{
            wx.showToast({
              title:prolist.msg,
              icon: 'error',
              duration: 2000
            })
          }
        }
      })
    } 
  },
  /***/

  /*跳转账号页*/
  onexisting(e){
    let that = this
    let openid = that.data.openid
    wx.navigateTo({
      url: '../myaccount/myaccount?openid='+openid,
    })
  },
  /*返回*/
  navigateBack() {
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})